package chapter06

/**
 * 特质的学习
 */
object Demo13_Trait {
  def main(args: Array[String]): Unit = {
    val student: Student13 = new Student13
    student.sayHello()
    student.study()
    student.dating()
    student.play()

  }
}
//定义一个父类
class Person13{
  val name:String = "Person"
  var age: Int = 22
  def sayHello(): Unit = {
    println("hello from: " + name)
  }
}

trait Young{
  //声明抽象和非抽象属性
  var age: Int
  val name: String = "young"

  //声明抽象和非抽象的方法
  def play(): Unit = {
    println(s"young person $name is playing")
  }

  def dating(): Unit
}

class Student13 extends Person13 with Young{
  //重写冲突的属性
  override val name: String = "student"
  //实现抽象方法
  def dating(): Unit = println(s"Student $name is dating")

  def study(): Unit = println(s"student $name is studying")

  //重写父类方法
  override def sayHello(): Unit = {
    super.sayHello()
    println(s"student $name sayHello")
  }
}